<?php
namespace Modules\Activity\Http\Controllers\Client\Lottery;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use \Modules\Activity\Entities\Lottery\Activity;
use \Modules\Activity\Entities\Lottery\Ticket;
// use \Modules\User\Entities\User;

use Validator;
use ThrowException;
use Auth;
use DB;

// 参与活动的用户（is_lucker_user）
class TicketController extends Controller
{
     // 某个人某个活动的签号列表
    public function myIndex(Request $req, $uuid)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $options = $req->all();
        $user = Auth::requireLoginUser();

        $activity = Activity::getEntity([
            'uuid' => $uuid
        ]);

        $where = [
            'activity_id' => $activity->id,
            'user_id' => $user->id
        ];

        if ($req->input('is_lucky')) {
            $where['status'] = 1;
        }

        $list = Ticket::getList([
            'where' => $where,
            'with' => ['invitee', 'activity'],
            'only' => [
                'id',
                'uuid',
                'number',
                'created_at',
                'source_type',
                'session',
                'invitee' => [
                    'name',
                    'headimg'
                ],
                'is_picked',
                'sku' => [
                    'title',
                    'number',
                    'thumb',
                    'type',
                    'score',
                    'redpack',
                    'coupon' => [
                        'id',
                        'uuid',
                        'title'
                    ]
                ],
                'order' => [
                    'id',
                    'uuid'
                ],
                'activity' => [
                    'title'
                ],
                'status'
            ]
        ]);

        $res = $list->generateListResponse();

        return $res;
    }
}
